package com.swing_pinea.render;

import com.swing_pinea.shape.PineaRect;

import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;

public class BgPanel extends JPanel {

    private List<Consumer<Graphics>> renderList;

    public BgPanel() {
        setLayout(new BorderLayout());
        renderList = new ArrayList<>();
    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        for (Consumer<Graphics> consumer : renderList) {
            consumer.accept(g);
        }
    }


    public void clear(Color color) {
        renderList.add(g -> {
            g.setColor(color);
            g.fillRect(0, 0, getWidth(), getHeight());
        });
    }

    public void fillRect(PineaRect rect, Color color) {
        renderList.add(g -> {
            g.setColor(color);
            g.fillRect((int) rect.x, (int) rect.y, (int) rect.w, (int) rect.h);
        });
    }

    public void drawImage(PineaImage image, float x, float y) {
        renderList.add(g -> {
            g.drawImage(image.getData(), (int) x, (int) y, null);
        });
    }
}
    